# @Filename:    02-张量的类型转换
# @Author:      王佳伟
# @Time:        2025-03-20 14:42
# @Describe:
import torch
import numpy as np

# 1. 将张量转换为 numpy 数组
# data_tensor = torch.tensor([2, 3, 4])
# data_numpy = data_tensor.numpy()
# print(type(data_tensor))
# print(type(data_numpy))

# 2. Numpy数组转换为张量
# data_numpy = np.array([2, 3, 4])
# data_tensor1 = torch.from_numpy(data_numpy)
# data_tensor2 = torch.tensor(data_numpy)
# print(type(data_numpy))
# print(type(data_tensor1))
# print(type(data_tensor2))

# 3. 标量张量和数字转换
data = torch.tensor([30,])
print(data.item())
data = torch.tensor(30)
print(data.item())
